﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LoomDataEmulator.Core
{
    public class LoomDataServer
    {
        #region Variables
        private string _filePath;
        private List<IMachine> _machines;
        private List<string> _commandFiles;
        private List<IProductionOrder> _productionOrders;
        private List<string> _dataFiles;
        #endregion

        #region Properties
        public List<IMachine> Machines
        {
            get { return _machines; }
            set { _machines = value; }
        }
        

        public List<IProductionOrder> ProductionOrders
        {
            get { return _productionOrders; }
            set { _productionOrders = value; }
        }

        public List<string> CommandFiles
        {
            get { return _commandFiles; }
            set { _commandFiles = value; }
        }

        public List<string> DataFiles
        {
            get { return _dataFiles; }
            set { _dataFiles = value; }
        }

        public string FilePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        #endregion

        #region Protected Methods

        protected void ProcessDataFiles()
        {
        }

        #endregion

        #region Public methods

        public void ProcessInput(object sender, FileSystemEventArgs e)
        {
            FileInfo fileINfo = new FileInfo(e.FullPath);
            
        }

        public void ProcessOutput()
        {
        }

        public List<IMachine> GetRunningMachines()
        {
            throw new NotImplementedException();
        }

        public void StopMachine(IMachine machine)
        {
        }

        public void Update()
        {
            throw new NotImplementedException();
        }
        #endregion

        public void PathToListen(string path)
        {
            FileSystemWatcher CMIFileWatcher = new FileSystemWatcher();
            CMIFileWatcher.Path = path;
            CMIFileWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            CMIFileWatcher.Filter = "*.cmi";
            CMIFileWatcher.Created += new FileSystemEventHandler(ProcessInput);
            CMIFileWatcher.EnableRaisingEvents = true;

            FileSystemWatcher DAIFileWatcher = new FileSystemWatcher();
            DAIFileWatcher.Path = path;
            DAIFileWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            DAIFileWatcher.Filter = "*.dai";
            DAIFileWatcher.Created += new FileSystemEventHandler(ProcessInput);
            DAIFileWatcher.EnableRaisingEvents = true;

        }


    }
}
